﻿namespace SageKing.Core.Contracts.FilterTypes;

public class NumberFieldFilterType<T> : BaseFieldFilterType where T : struct
{
    private static IEnumerable<SageKingFilterCompareOperator> _supportedCompareOperators = new[]
    {
        SageKingFilterCompareOperator.Equals,
        SageKingFilterCompareOperator.NotEquals,
        SageKingFilterCompareOperator.GreaterThan,
        SageKingFilterCompareOperator.LessThan,
        SageKingFilterCompareOperator.GreaterThanOrEquals,
        SageKingFilterCompareOperator.LessThanOrEquals
    };

    public NumberFieldFilterType()
    {
        SupportedCompareOperators = _supportedCompareOperators;
    }

    public override Expression GetFilterExpression(SageKingFilterCompareOperator compareOperator, Expression leftExpr, Expression rightExpr)
    {
        return base.GetFilterExpression(compareOperator, leftExpr, Expression.Convert(rightExpr, leftExpr.Type));
    }
}
